package com.demo2do.boyle.client.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.demo2do.boyle.common.entity.advertisement.Advertisement;
import com.demo2do.boyle.common.entity.customer.Customer;
import com.demo2do.boyle.common.entity.task.Task;
import com.demo2do.core.persistence.GenericDaoSupport;

/**
 * 
 * @author mohanlan
 *
 */
@Repository("taskDaoSupport")
public class TaskDaoSupport {
	
	@Autowired
	private GenericDaoSupport genericDaoSupport;
	
	/**
	 * 
	 * @param customer
	 * @param advertisement
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Task loadTask(Customer customer, Advertisement advertisement) {
		
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("customer", customer);
		parameters.put("advertisement", advertisement);
		
		List<Task> tasks = genericDaoSupport.searchForList("FROM Task task WHERE task.customer = :customer AND task.advertisement = :advertisement", parameters);
		
		return tasks.isEmpty() ? null : tasks.get(0);
	}

}
